#include <glibmm-2.4/glibmm/refptr.h>
#include <gtkmm-3.0/gtkmm/widget.h>
#include <gtkmm-3.0/gtkmm/container.h>
#include <gdkmm/general.h>
#include <gtkmm/button.h>
#include <gtkmm-3.0/gtkmm/image.h>
#include <gtkmm-3.0/gtkmm/stock.h>
#include "VentanaMenuPrincipal.h"
#include "Excepcion.h"

#define		PATH_LOGO		"../Recursos/Fondo Menu.png"
#define		PATH_ICONO		"../Recursos/diseñador_icono.png"

VentanaMenuPrincipal::VentanaMenuPrincipal() :
		_salirButton(Gtk::Stock::QUIT),
		_singleplayerButton("Single player"),
		_multiplayerButton("Multi player") {
	_ventanaNombreJugador = NULL;

	Glib::RefPtr<Gdk::Pixbuf> imagenLogo =	Gdk::Pixbuf::create_from_file(
			PATH_LOGO)->scale_simple(600, 400, Gdk::INTERP_NEAREST);

	_logo.set(imagenLogo);
	_grid = new Gtk::Grid;

	set_title("Cerditos Furiosos - Menu");
	set_position(Gtk::WIN_POS_CENTER);
	set_default_size(800, 400);
	set_icon_from_file(PATH_ICONO);

	_singleplayerButton.signal_clicked().connect(sigc::mem_fun(
			*this, &VentanaMenuPrincipal::on_JugarSingleplayer_clicked));
	_multiplayerButton.signal_clicked().connect(sigc::mem_fun(
			*this, &VentanaMenuPrincipal::on_JugarMultiplayer_clicked));
	_salirButton.signal_clicked().connect(sigc::mem_fun(
			*this, &VentanaMenuPrincipal::on_Salir_clicked));

	_salirButton.set_focus_on_click(false);
	_singleplayerButton.set_focus_on_click(false);
	_multiplayerButton.set_focus_on_click(false);

	_grid->set_hexpand(true);
	_grid->set_vexpand(true);
	_grid->set_halign(Gtk::ALIGN_CENTER);
	_grid->set_valign(Gtk::ALIGN_END);

	_logo.set_size_request(100, 100);
	_logo.set_app_paintable(true);

	add(*_grid);

	_grid->set_column_spacing(5);
	_grid->set_row_spacing(10);

	_grid->attach(_singleplayerButton, 4, 1, 2, 1);
	_grid->attach(_multiplayerButton, 4, 2, 2, 1);
	_grid->attach(_salirButton, 4, 3, 2, 1);
	_grid->attach(_logo, 0, 0, 10, 1);

	set_border_width(10);
	set_resizable(false);
}

VentanaMenuPrincipal::~VentanaMenuPrincipal() {
	delete _grid;
}

void VentanaMenuPrincipal::on_JugarMultiplayer_clicked() {
	_ventanaNombreJugador = new VentanaEntradaNombreJugador();
}

void VentanaMenuPrincipal::on_JugarSingleplayer_clicked() {
	// Falta implementar
}

void VentanaMenuPrincipal::on_Salir_clicked() {
	hide();
}

void VentanaMenuPrincipal::Show() {
	this->show_all_children(true);
}

void VentanaMenuPrincipal::Hide() {
	this->hide();
}
